﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media.Imaging;
using Jungle_Timers.Helpers;

namespace Jungle_Timers.Entities
{
    public class ActiveTimerItem : ITimedItem, INotifyPropertyChanged
    {
        public TimerNames Name { get; set; }
        public string ImagePath { get; set; }
        public TimeSpan CoolDown { get; set; }

        public double PercentLeft { get { return ElapsedTime.TotalSeconds / CoolDown.TotalSeconds; } }

        public TimeSpan TimeRemaining { get { return new TimeSpan(0,0,(int)(CoolDown.TotalSeconds - ElapsedTime.TotalSeconds)); } }

        public TimeSpan ElapsedTime
        {
            get { return _elapsedTime; }
            set
            {
                _elapsedTime = value;
                NotifyPropertyChanged("PercentLeft");
                NotifyPropertyChanged("TimeRemaining");
            }
        }

        private TimeSpan _elapsedTime;

        public ActiveTimerItem(TimerNames timerName)
        {
            ImagePath = "Data\\Images\\Icons\\" + timerName + ".png";
            CoolDown = new TimeSpan(0,0,(int)timerName);
            StartTime = DateTime.Now;
        }
        
        public DateTime StartTime { get; set; }

        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }

    public interface ITimedItem
    {
        TimeSpan CoolDown { get; set; }
        TimeSpan ElapsedTime { get; set; }
        DateTime StartTime { get; set; }
    }
}
